﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Windows.Threading;
using System.ComponentModel;

namespace MockSmtpServer
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private ObservableCollection<SmtpMailMessage> messages;
        private SmtpServer server;

        public ObservableCollection<SmtpMailMessage> Messages
        {
            get { return messages; }
        }

        public MainWindow()
        {
            messages = new ObservableCollection<SmtpMailMessage>();

            InitializeComponent();

            server = new SmtpServer();
            server.MessageReceived += new EventHandler<SmtpMessageReceivedEventArgs>(server_MessageReceived);
        }

        private void AddMessage(SmtpMailMessage message)
        {
            messages.Add(message);
        }

        private void server_MessageReceived(object sender, SmtpMessageReceivedEventArgs e)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, new Action<SmtpMailMessage>(AddMessage), e.Message);
        }

        private void Image_MouseDown(object sender, MouseButtonEventArgs e)
        {
            AboutWindow about = new AboutWindow();
            about.ShowDialog();
        }
    }
}
